package com.gem.day12;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

/**
 * 本类用来演示Java集合之Properties
 * 
 * 特点:
 * Properties是一种线程安全的HashMap集合,等价于HashTable,
 * 并且Properties的键值必须是String类
 * 
 * @author easonsy
 * 2020年8月3日 下午2:49:45
 */
public class PropertiesDemo {
	public static void main(String[] args) throws UnsupportedEncodingException {
		//用法一:获取系统信息
		/*Properties properties = System.getProperties();
		System.out.println(properties.getProperty("os.name"));
		System.out.println(properties.getProperty("os.arch"));
		properties.list(System.out);*/

		System.out.println("-----------------------------");

		//创建一个空的Properties集合
		Properties properties = new Properties();
		//加载本地Properties配置文件
		try {
			properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		//字符串硬编码
		System.out.println(properties.getProperty("username"));
		//System.out.println(new String(properties.getProperty("username").getBytes("ISO-8859-1"), "UTF-8"));
		System.out.println(properties.getProperty("password"));
	}
}
